#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <dlfcn.h>
#include "inkview.h"

#include "iface.h"
#include "Table.h"

CTable table = CTable();
ifont *arial8n, *arial12, *arialb12, *cour16, *cour24, *times20;
void msg(char *s) {

	FillArea(350, 770, 250, 20, WHITE);
	SetFont(arialb12, BLACK);
	DrawString(350, 770, s);
	PartialUpdate(350, 770, 250, 20);

}
int main_handler( int type, int par1, int par2 )
{

	std::cout << inf << "main handler " << type << "(" << par1 << "," << par2 << std::endl;
	// fflush(stdout);

	if( type == 32 /* changed orientation */ )
	{
		CIface::SetOrientation( par1 );
		table.Relayout();
        //table.Display( true );
	}
	
    if (type == EVT_INIT) {

		CIface::SetOrientation( 1 );
        // occurs once at startup, only in main handler 
		table.Handle(DO_SETUP);
        //table.Display( true );
    }
    if (type == EVT_KEYPRESS) 
    {

        switch (par1) 
        {

          case KEY_OK:
            table.Handle( DO_ACTION );
            break;

          case KEY_BACK:
            CloseApp();
            break;

          case KEY_LEFT:
            table.Handle( DO_MOVELEFT );
            break;

          case KEY_RIGHT:
            table.Handle( DO_MOVERIGHT );
            break;

          case KEY_UP:
            table.Handle( DO_SELPLUS );
            break;

          case KEY_DOWN:
            table.Handle( DO_SELMINUS );
            break;

          case KEY_MUSIC:
            msg("KEY_MUSIC");
            break;

          case KEY_MENU:
            msg("KEY_MENU");
            break;

          case KEY_DELETE:
            msg("KEY_DELETE");
            break;

        }  // KEYPRES SWITCHER
		
    }    // IF KEYPRESS
  
  if (type == EVT_EXIT) {
    // occurs only in main handler when exiting or when SIGINT received.
    // save configuration here, if needed
  } //EXIT EVENT

  if (type == EVT_SHOW) {

    // occurs when this event handler becomes active
//    mainscreen_repaint();
  }  

   return 0;
}

int main( int argc, char** args )
{
    
    InkViewMain(main_handler);
        
}


